/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.discount.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.discount.entity.DiscountBrand;
import com.jeesite.modules.discount.service.DiscountBrandService;

/**
 * 品牌Controller
 * @author czp
 * @version 2018-07-08
 */
@Controller
@RequestMapping(value = "${adminPath}/discount/discountBrand")
public class DiscountBrandController extends BaseController {

	@Autowired
	private DiscountBrandService discountBrandService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DiscountBrand get(String id, boolean isNewRecord) {
		return discountBrandService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("discount:discountBrand:view")
	@RequestMapping(value = {"list", ""})
	public String list(DiscountBrand discountBrand, Model model) {
		model.addAttribute("discountBrand", discountBrand);
		return "modules/discount/discountBrandList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("discount:discountBrand:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DiscountBrand> listData(DiscountBrand discountBrand, HttpServletRequest request, HttpServletResponse response) {
		Page<DiscountBrand> page = discountBrandService.findPage(new Page<DiscountBrand>(request, response), discountBrand); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("discount:discountBrand:view")
	@RequestMapping(value = "form")
	public String form(DiscountBrand discountBrand, Model model) {
		model.addAttribute("discountBrand", discountBrand);
		return "modules/discount/discountBrandForm";
	}

	/**
	 * 保存品牌
	 */
	@RequiresPermissions("discount:discountBrand:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DiscountBrand discountBrand) {
		discountBrandService.save(discountBrand);
		return renderResult(Global.TRUE, "保存品牌成功！");
	}
	
	/**
	 * 停用品牌
	 */
	@RequiresPermissions("discount:discountBrand:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DiscountBrand discountBrand) {
		discountBrand.setStatus(DiscountBrand.STATUS_DISABLE);
		discountBrandService.updateStatus(discountBrand);
		return renderResult(Global.TRUE, "停用品牌成功");
	}
	
	/**
	 * 启用品牌
	 */
	@RequiresPermissions("discount:discountBrand:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DiscountBrand discountBrand) {
		discountBrand.setStatus(DiscountBrand.STATUS_NORMAL);
		discountBrandService.updateStatus(discountBrand);
		return renderResult(Global.TRUE, "启用品牌成功");
	}
	
	/**
	 * 删除品牌
	 */
	@RequiresPermissions("discount:discountBrand:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DiscountBrand discountBrand) {
		discountBrandService.delete(discountBrand);
		return renderResult(Global.TRUE, "删除品牌成功！");
	}
	
}